package com.alks.function.mapper.chengKong;

import com.alks.common.data.dto.SysUserTokenDTO;
import com.alks.entity.data.entity.*;
import com.alks.entity.data.entity.dispatch.OemLotHead;
import com.alks.entity.data.entity.dispatch.SysOperLog;
import com.alks.entity.data.entity.excel.PcAggScheduleExcel;
import com.alks.function.data.dto.PcLotHeadCountDto;
import com.alks.function.data.dto.biocontrol.factoryQuery.StkAccDto;
import com.alks.function.data.dto.biocontrol.webwork.DelDetDto;
import com.alks.function.data.dto.biocontrol.webwork.DeliveryListDto;
import com.alks.function.data.dto.chengKong.export.PunchingExportVo;
import com.alks.function.data.dto.chengKong.produce.*;
import com.alks.function.data.dto.pcfactoryquery.PcMtlAttributeDto;
import com.alks.function.data.dto.pcfactoryquery.PcMtlByLotHeadDto;
import com.alks.function.data.dto.procurement.CleanDataDto;
import com.alks.function.data.dto.procurement.PurchaseOrderDto;
import com.alks.function.data.dto.produce.SuppDispatchPrintDto;
import com.alks.function.data.request.chengKong.PcLotDetailUpdateRequest;
import com.alks.function.data.request.chengKong.PcLotHeadRequest;
import com.alks.function.data.request.chengKong.PcLotHeadRequest2;
import com.alks.function.data.request.chengKong.PoNumberRequest;
import com.alks.function.data.request.factoryquery.LotStyleRerquest;
import com.alks.function.data.request.factoryquery.SpMtlHeadRequest;
import com.alks.function.data.request.factorywork.PcDhLotRequest;
import com.alks.function.data.request.procurement.LotAndMtlRequest;
import com.alks.function.data.request.produce.SuppDispatchPrintRequest;
import com.alks.function.data.request.stockdept.pcfactorystockwork.PcCodeRequest;
import com.alks.function.data.vo.pcfactoryWork.OutUnitPriceVo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Param;
import org.mapstruct.Mapper;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Mapper
public interface PcLotHeadMapper extends BaseMapper<PcLotHead> {

    /**
     * 查询所有指令信息
     * @param r
     * @param companyId
     * @return
     */
    List<PcLotHeadDto> getStyleDetails(@Param("r") PcLotHeadRequest r,
                                       @Param("dto") SysUserTokenDTO dto);

    List<PcLotHeadDto2> getStyleDetails2(@Param("r") PcLotHeadRequest r,
                                       @Param("companyId") String companyId);

    /**
     * 统计订单数量预补数量
     * @param r
     * @param companyId
     * @return
     */
    PcLotHeadCountDto orderCount(@Param("r") PcLotHeadRequest r,
                                 @Param("dto") SysUserTokenDTO dto);

    List<PcLotHeadCountDto> count(PcLotHeadRequest request);

    /**
     * 查询po号码明细
     * @param lotNo
     * @return
     */
    List<PcLotGroupDto> PoNumberDetails(@Param("lotNo") String lotNo,
                                        @Param("companyId") String companyId);

    /**
     * 查询码数
     * @return
     */
    List<PcLotSizeSeqDto> getSize(@Param("sizeCode") String sizeCode,
                                  @Param("companyId") String companyId);

    /**
     * 指令配码明细
     * @param lotNo
     * @return
     */
    List<PcLotDetailDto> getCodeDetails(@Param("lotNo")String lotNo,
                                        @Param("companyId") String companyId);

    List<PcLotDetailDto> getCodeDetails3(@Param("lotNo")String lotNo,
                                        @Param("companyId") String companyId);

    /*获得指令和号码的对应qty序号*/
    List<PcLotDetailDto2> getCodeDetails4(@Param("lotNo")String lotNo,
                                          @Param("companyId") String companyId, String sizeNo);
    /*可以根据qty(?)和鞋码互相查qty和鞋码*/
    List<PcLotDetailDto2> getCodeDetails5(PcCodeRequest request);

    /**
     * 号码明细（指令明细配码）
     * @param lotNo
     * @return
     */
    List<PcLotDetailDto> getCodeDetails2(@Param("lotNo")String lotNo,
                                        @Param("style") String style,
                                        @Param("companyId") String companyId);

    /**
     * 查询指令明细数量
     * @param lotNo
     * @return
     */
    PcLotHeadCountDto getCodeDetailsSum(@Param("lotNo")String lotNo,
                                        @Param("companyId") String companyId);

    /**
     * 查询指令用量明细
     * @param lotNo
     * @param companyId
     * @return
     */
    List<PcLotUsageDto> getUsageDetails(@Param("lotNo") String lotNo, @Param("companyId") String companyId);

    /*根据查询指令用量明细*/
    List<PcLotUsageDto> getUsageDetailsByLotAndMtl(@Param("request") LotAndMtlRequest request);

    /*批量根据指令和材料信息查询*/
    List<PcLotUsageDto> getUsageDetailsByLotAndMtlBatch(@Param("request") Set<PurchaseOrderDto> request);

    /**
     * 型体配楦明细
     * @param style
     * @param companyId
     * @return
     */
    List<SdStyleSizeDto> getStyleShoeLastDetails(@Param("style") String style, @Param("companyId") String companyId);

    /**
     * 配色BOM资料
     * @return
     */
    List<SdBomPartNew2Dto> getBOMDetails(PcLotHeadRequest2 request);

    /**
     * 根据指令查询补制详情
     * @param lotNo
     * @return
     */
    List<PcMtlAttributeDto> querySupportByLotNo(List lotNo);

    /*材料配套查询表头*/
    List<PcMtlByLotHeadDto> getMtlHead(SpMtlHeadRequest request);

    /*厂商总览*/
    List<String> queryVendor();

    @Update("UPDATE PC_STYLE_PHOTO SET PHOTO_PATH = #{photoPath} WHERE STYLE = #{style} AND COLOR= #{color}")
    Integer updatePhotoByStyleColor(@Param("photoPath") String photoPath,@Param("style")String style,@Param("color") String color);

    /*判断是否存在数据*/
    Integer queryCount(@Param("lotNo") String lotNo, @Param("companyId") String companyId);

    /**
     * 大底入货号码查询
     * @param lotNo
     * @return
     */
    @Select("select SIZE_NO, ORDER_QTY, SURPLUS_QTY from PC_LOT_DETAIL_SOLE where LOT_NO = #{lotNo} and COMPANY_ID=#{companyId} order by SEQ_NO ASC")
    List<PcLotDetailDto> getSoleDetails(@Param("lotNo") String lotNo,
                                        @Param("companyId") String companyId);

    /**
     * 统计大底入货号码数量
     * @param lotNo
     * @return
     */
    @Select("select sum(ORDER_QTY) as orderCount, sum(SURPLUS_QTY) as surplusCount from PC_LOT_DETAIL_SOLE where LOT_NO = #{lotNo} and COMPANY_ID=#{companyId}")
    PcLotHeadCountDto getSoleDetailsSum(@Param("lotNo") String lotNo,
                                        @Param("companyId") String companyId);

    /**
     * 鞋面生产号码查询
     * @param lotNo
     * @return
     */
    @Select("select SIZE_NO, ORDER_QTY, SURPLUS_QTY from PC_LOT_DETAIL_STITCH where LOT_NO = #{lotNo} and COMPANY_ID=#{companyId} order by SEQ_NO ASC")
    List<PcLotDetailDto> getStitchDetails(@Param("lotNo") String lotNo,
                                          @Param("companyId") String companyId);

    /**
     * 统计鞋面生产号码数量
     * @param lotNo
     */
    @Select("select sum(ORDER_QTY) as orderCount, sum(SURPLUS_QTY) as surplusCount from PC_LOT_DETAIL_STITCH where LOT_NO = #{lotNo} and COMPANY_ID=#{companyId}")
    PcLotHeadCountDto getStitchDetailsSum(@Param("lotNo") String lotNo,
                                          @Param("companyId") String companyId);

    /**
     * 成型生产号码查询
     * @param lotNo
     * @return
     */
    @Select("select SIZE_NO, ORDER_QTY, SURPLUS_QTY from PC_LOT_DETAIL_LAST where LOT_NO = #{lotNo} and COMPANY_ID=#{companyId} order by SEQ_NO ASC")
    List<PcLotDetailDto> getLastDetails(@Param("lotNo") String lotNo,
                                        @Param("companyId") String companyId);

    /**
     * 统计成型生产号码数量
     * @param lotNo
     * @return
     */
    @Select("select sum(ORDER_QTY) as orderCount, sum(SURPLUS_QTY) as surplusCount from PC_LOT_DETAIL_LAST where LOT_NO = #{lotNo} and COMPANY_ID=#{companyId}")
    PcLotHeadCountDto getLastDetailsSum(@Param("lotNo") String lotNo,
                                        @Param("companyId") String companyId);

    /**
     * 删除大底入货号码
     * @param lotNo
     */
    @Delete("delete from PC_LOT_DETAIL_SOLE where LOT_NO = #{lotNo} and COMPANY_ID=#{companyId}")
    void delSoleDetails(@Param("lotNo") String lotNo,
                        @Param("companyId") String companyId);

    /**
     * 新增大底入货号码
     * @param pcLotDetails
     */
    @Insert({
            "<script>",
            "insert into PC_LOT_DETAIL_SOLE(LOT_NO,SIZE_NO,ORDER_QTY,SURPLUS_QTY,SEQ_NO,COMPANY_ID)",
            "values ",
            "<foreach collection='list' item='item' separator=','>",
            "(#{item.lotNo},#{item.sizeNo},#{item.orderQty},#{item.surplusQty},#{item.seqNo},#{item.companyId})",
            "</foreach>",
            "</script>"
    })
    void addSoleDetails(@Param("list") List<PcLotDetail> pcLotDetails);

    /**
     * 删除鞋面生产号码
     * @param lotNo
     * @param companyId
     */
    @Delete("delete from PC_LOT_DETAIL_STITCH where LOT_NO = #{lotNo} and COMPANY_ID=#{companyId}")
    void delStitchDetails(@Param("lotNo") String lotNo,
                          @Param("companyId") String companyId);

    /**
     * 新增鞋面生产号码
     * @param pcLotDetails
     */
    @Insert({
            "<script>",
            "insert into PC_LOT_DETAIL_STITCH(LOT_NO,SIZE_NO,ORDER_QTY,SURPLUS_QTY,SEQ_NO,COMPANY_ID)",
            "values ",
            "<foreach collection='list' item='item' separator=','>",
            "(#{item.lotNo},#{item.sizeNo},#{item.orderQty},#{item.surplusQty},#{item.seqNo},#{item.companyId})",
            "</foreach>",
            "</script>"
    })
    void addStitchDetails(@Param("list") List<PcLotDetail> pcLotDetails);

    /**
     * 删除成型生产号码
     * @param lotNo
     * @param companyId
     */
    @Delete("delete from PC_LOT_DETAIL_LAST where LOT_NO = #{lotNo} and COMPANY_ID=#{companyId}")
    void delLastDetails(@Param("lotNo") String lotNo,
                        @Param("companyId") String companyId);

    /**
     * 新增成型生产号码
     * @param pcLotDetails
     */
    @Insert({
            "<script>",
            "insert into PC_LOT_DETAIL_LAST(LOT_NO,SIZE_NO,ORDER_QTY,SURPLUS_QTY,SEQ_NO,COMPANY_ID)",
            "values ",
            "<foreach collection='list' item='item' separator=','>",
            "(#{item.lotNo},#{item.sizeNo},#{item.orderQty},#{item.surplusQty},#{item.seqNo},#{item.companyId})",
            "</foreach>",
            "</script>"
    })
    void addLastDetails(@Param("list") List<PcLotDetail> pcLotDetails);

    /**
     * 设置中间码
     * @param lotNo
     * @param mSize
     */
    @Update("update PC_LOT_HEAD set M_SIZE=#{mSize} where LOT_NO=#{lotNo} and COMPANY_ID=#{companyId}")
    void updateBymSize(@Param("lotNo") String lotNo,
                       @Param("mSize") String mSize,
                       @Param("companyId")String companyId);

    /**
     * 检核
     * @param lotNo
     * @param userName
     * @param cfmFlag
     * @param now
     */
    @Update("update PC_LOT_HEAD set CFM_FLAG=#{cfmFlag},CFM_DATE=#{now},CFM_USER=#{userName} where LOT_NO=#{lotNo} and COMPANY_ID=#{companyId}")
    void updateLotNoCheckOut(@Param("lotNo") String lotNo,
                             @Param("companyId") String companyId,
                             @Param("userName") String userName,
                             @Param("cfmFlag") String cfmFlag,
                             @Param("now") LocalDateTime now);

    /**
     * 判断po号码是否是否存在
     * @param groupNo
     * @param lotNo
     * @param companyId
     */
    @Select("select count(0) from PC_LOT_GROUP where GROUP_NO=#{groupNo} and LOT_NO=#{lotNo} and COMPANY_ID=#{companyId}")
    Integer getPoNumberDetail(@Param("groupNo") String groupNo,
                           @Param("lotNo") String lotNo,
                           @Param("companyId") String companyId);

    /**
     * 修改po号码明细
     * @param pcLotGroup
     */
    @Update("update PC_LOT_GROUP set PO_NO=#{poNo},CASE_TYPE=#{caseType},SIZE_NOTICE=#{sizeNotice},QTY1=#{qty1},QTY2=#{qty2},QTY3=#{qty3},QTY4=#{qty4},QTY5=#{qty5},QTY6=#{qty6}," +
            "QTY7=#{qty7},QTY8=#{qty8},QTY9=#{qty9},QTY10=#{qty10},QTY11=#{qty11},QTY12=#{qty12},QTY13=#{qty13},QTY14=#{qty14},QTY15=#{qty15}," +
            "QTY16=#{qty16},QTY17=#{qty17},QTY18=#{qty18},QTY19=#{qty19},QTY20=#{qty20},QTY21=#{qty21},QTY22=#{qty22},QTY23=#{qty23},QTY24=#{qty24}," +
            "QTY25=#{qty25},QTY26=#{qty26},QTY27=#{qty27},QTY28=#{qty28},QTY29=#{qty29},QTY30=#{qty30},QTY31=#{qty31},QTY32=#{qty32},QTY33=#{qty33}," +
            "QTY34=#{qty34},QTY35=#{qty35},QTY36=#{qty36} where GROUP_NO=#{groupNo} and LOT_NO=#{lotNo} and COMPANY_ID=#{companyId}")
    void updatePoNumberDetail(PcLotGroup pcLotGroup);

    /**
     * 删除指令号码明细
     * @param lotNo
     * @param companyId
     * @param delList
     */
    @Delete({
            "<script>",
            "delete from PC_LOT_DETAIL",
            "where LOT_NO = #{lotNo} and COMPANY_ID=#{companyId}",
            "and SIZE_NO in",
            "<foreach item='t' collection='delList' open='(' separator=',' close=')'>",
            "#{t.sizeNo}",
            "</foreach>",
            "</script>"
    })
    void delPcLotDetail(@Param("lotNo") String lotNo, @Param("companyId") String companyId, @Param("delList") List<PoNumberRequest> delList);

    /**
     * 删除指令号码明细2
     * @param lotNo
     * @param companyId
     */
    @Delete("delete from PC_LOT_DETAIL where LOT_NO = #{lotNo} and COMPANY_ID=#{companyId} and ORDER_QTY=0")
    void delPcLotDetail2(@Param("lotNo") String lotNo, @Param("companyId") String companyId);
    /**
     * 修改指令号码明细订单数
     * @param lotNo
     * @param companyId
     * @param updateList
     */
    @Update({
            "<script>",
            "<foreach item='t' collection='updateList' separator=';'>",
            "update PC_LOT_DETAIL",
            "set ORDER_QTY =",
            "#{t.orderQty}",
            "where LOT_NO = #{lotNo} and COMPANY_ID=#{companyId}",
            "and SIZE_NO =#{t.sizeNo}",
            "</foreach>",
            "</script>"
    })
    void updatePcLotDetail(@Param("lotNo") String lotNo, @Param("companyId") String companyId, @Param("updateList") List<PoNumberRequest> updateList);

    /**
     * 新增po号码明细
     * @param pcLotGroup
     */
    @Insert("  INSERT INTO PC_LOT_GROUP (COMPANY_ID, LOT_NO, GROUP_NO, PO_NO, CASE_TYPE, QTY1, QTY2, QTY3, QTY4, QTY5, QTY6, QTY7, QTY8, QTY9, QTY10, QTY11, QTY12, QTY13, QTY14, QTY15, QTY16, QTY17, QTY18, QTY19, QTY20," +
            " QTY21, QTY22, QTY23, QTY24, QTY25, QTY26, QTY27, QTY28, QTY29, QTY30, QTY31, QTY32, QTY33, QTY34, QTY35, QTY36,QTY37,QTY38,QTY39,QTY40, SIZE_NOTICE, CASE_QTY, GROUP_NAME, DELIVERY_DATE, PORT_NAME)" +
            "  VALUES (#{companyId}, #{lotNo}, #{groupNo}, #{poNo}, #{caseType}, #{qty1}, #{qty2}, #{qty3}, #{qty4}, #{qty5}, #{qty6}, #{qty7}, #{qty8}, #{qty9}, #{qty10}, #{qty11}, #{qty12}, #{qty13}, #{qty14}, #{qty15}, #{qty16}, #{qty17}, #{qty18}, #{qty19}, #{qty20}," +
            " #{qty21}, #{qty22}, #{qty23}, #{qty24}, #{qty25}, #{qty26}, #{qty27}, #{qty28}, #{qty29}, #{qty30}, #{qty31}, #{qty32}, " +
            "#{qty33}, #{qty34}, #{qty35}, #{qty36},#{qty37},#{qty38},#{qty39},#{qty40}, #{sizeNotice}, #{caseQty}, #{groupName}, #{deliveryDate}, #{portName})")
    void addPoNumberDetail(PcLotGroup pcLotGroup);

    /**
     * 新增指令号码明细
     * @param pcLotDetailList
     */
    @Insert({
            "<script>",
            "INSERT INTO PC_LOT_DETAIL (LOT_NO, SIZE_NO, ORDER_QTY, SURPLUS_QTY, SEQ_NO, CUT_SIZE, SOLE_SIZE, LAST_SIZE, COMPANY_ID, L_SURPLUS_QTY, S_SURPLUS_QTY)",
            "VALUES",
            "<foreach collection='pcLotDetailList' item='t' separator=','>",
            "(#{t.lotNo}, #{t.sizeNo}, #{t.orderQty}, #{t.surplusQty}, #{t.seqNo}, #{t.cutSize}, #{t.soleSize}, #{t.lastSize}, #{t.companyId}, #{t.lSurplusQty}, #{t.sSurplusQty})",
            "</foreach>",
            "</script>"
    })
    void addPcLotDetail(@Param("pcLotDetailList") List<PcLotDetail> pcLotDetailList);

    /**
     * 修改订单数量与预补数量
     * @param lotNo
     * @param orderCount
     * @param surplusCount
     * @param companyId
     */
    @Update("update PC_LOT_HEAD set ORDER_QTY=#{orderCount},SURPLUS_QTY=#{surplusCount},UPDATE_TIME=now() where LOT_NO=#{lotNo} and COMPANY_ID=#{companyId}")
    void updateOrderQty(@Param("lotNo") String lotNo,
                        @Param("orderCount") Integer orderCount,
                        @Param("surplusCount") Integer surplusCount,
                        @Param("companyId") String companyId);

    /**
     * 删除po号码明细
     * @param lotNo
     * @param groupNo
     * @param companyId
     */
    @Delete("delete from PC_LOT_GROUP where LOT_NO=#{lotNo} and GROUP_NO=#{groupNo} and COMPANY_ID=#{companyId}")
    void delPcLotGroup(@Param("lotNo") String lotNo,
                       @Param("groupNo") String groupNo,
                       @Param("companyId") String companyId);

    /**
     * 修改指令号码预补数
     * @param request
     */
    @Update("update PC_LOT_DETAIL set SURPLUS_QTY=#{surplusQty} where LOT_NO = #{lotNo} and SIZE_NO =#{sizeNo} and COMPANY_ID=#{companyId}")
    void updatePcLotDetailSurplus(PcLotDetailUpdateRequest request);

    /**
     * 查询型体颜色编码
     * @return
     * @param companyId
     */
    @Select("SELECT STYLE_NO,STYLE_COLOR,COLOR_CODE from SD_BOM_HEAD_NEW2 where COMPANY_ID=#{companyId} GROUP BY STYLE_NO,STYLE_COLOR,COLOR_CODE ORDER BY STYLE_NO,STYLE_COLOR,COLOR_CODE")
    List<StyleDetailDto> getStyleToDetail(String companyId);

    /**
     * 查询品牌
     * @param companyId
     */
    @Select("SELECT CUSTOM from PC_LOT_HEAD where COMPANY_ID=#{companyId} GROUP BY CUSTOM ORDER BY CUSTOM")
    List<String> getCustom(String companyId);

    /**
     * 查询冲刀
     * @param companyId
     * @return
     */
    @Select("SELECT CUT_NO from PC_LOT_HEAD where COMPANY_ID=#{companyId} GROUP BY CUT_NO ORDER BY CUT_NO")
    List<String> getCutNo(String companyId);

    /**
     * 查询楦头
     * @param companyId
     * @return
     */
    @Select("SELECT LAST_NO from PC_LOT_HEAD where COMPANY_ID=#{companyId} GROUP BY LAST_NO ORDER BY LAST_NO")
    List<String> getLaseNo(String companyId);

    /**
     * 查询大底厂商
     * @param companyId
     * @return
     */
    @Select("SELECT SOLE_VENDOR from PC_LOT_HEAD where COMPANY_ID=#{companyId} GROUP BY SOLE_VENDOR ORDER BY SOLE_VENDOR")
    List<String> getSoleVendor(String companyId);

    /**
     * 查询底模
     * @param companyId
     * @return
     */
    @Select("SELECT MOLD_NO from PC_LOT_HEAD where COMPANY_ID=#{companyId} GROUP BY MOLD_NO ORDER BY MOLD_NO")
    List<String> getMoldNo(String companyId);

    /**
     * 查询季度
     * @param companyId
     * @return
     */
    @Select("SELECT SEASON from PC_LOT_HEAD where COMPANY_ID=#{companyId} GROUP BY SEASON ORDER BY SEASON")
    List<String> getSeason(String companyId);

    @Select("SELECT a.CUST_NO,a.DEV_CODE,a.SOLE_VENDOR,b.LAST_MOLD,b.CUT_TOOL,b.SOLE_PART FROM SD_STYLE a LEFT JOIN SD_STYLE_TYPE b on a.STYLE_NO=b.STYLE_NO AND a.COMPANY_ID=b.COMPANY_ID where a.STYLE_NO=#{styleNo} and a.COMPANY_ID=#{companyId}")
    StyleDataDto getStyleCondition(@Param("styleNo") String styleNo, @Param("companyId") String companyId);

    /**
     * 查询全码用量
     * @param style
     * @param color
     * @param partName
     * @param segment
     * @param companyId
     */
    @Select("select COMPANY_ID,STYLE_NO,STYLE_COLOR,PART_NAME,SEGMENT,SIZE_FROM,MTL_USAGE from SD_BOM_USAGE_NEW2 where STYLE_NO=#{style} and STYLE_COLOR=#{color} and PART_NAME=#{partName}" +
            "and SEGMENT=#{segment} and COMPANY_ID=#{companyId} order by SIZE_FROM")
    List<SdBomUsageNew2> getSdBomUsageNew2(@Param("style") String style,
                                           @Param("color") String color,
                                           @Param("partName") String partName,
                                           @Param("segment") String segment,
                                           @Param("companyId") String companyId);

    /**
     * 删除指令用量明细
     * @param lotNo
     * @param companyId
     */
    @Delete("delete from PC_LOT_USAGE where LOT_NO=#{lotNo} and COMPANY_ID=#{companyId}")
    void delPcLotUsage(@Param("lotNo") String lotNo, @Param("companyId") String companyId);

    /**
     * 删除指令用量子材料
     * @param lotNo
     * @param companyId
     */
    @Delete("delete from PC_LOT_USAGE_FIT where LOT_NO=#{lotNo} and COMPANY_ID=#{companyId}")
    void delPcLotUsageFit(@Param("lotNo") String lotNo, @Param("companyId") String companyId);

    /**
     * 生成指令用量明细
     * @param pcLotUsageList
     */
    @Insert({"<script>",
            "INSERT INTO PC_LOT_USAGE (COMPANY_ID, LOT_NO, SEQ_NO, PART_NAME, SEGMENT, MTL_NO, MTL_COLOR, MTL_NAME, SIZE1, SIZE2, MTL_SPEC, MTL_UNIT, `USAGE`, USAGE_TYPE, MTL_TYPE_NO, VENDOR, STD_USAGE, TTL_USAGE, REMARK, SUM_USAGE, DRAW_DEPT, MTL_PROPERTY, ADD_USAGE, MTL_LEVEL)",
            "VALUES",
            "<foreach collection='pcLotUsageList' item='t' separator=','>",
            "(#{t.companyId}, #{t.lotNo}, #{t.seqNo}, #{t.partName}, #{t.segment}, #{t.mtlNo}, #{t.mtlColor}, #{t.mtlName}, #{t.size1}, #{t.size2}, #{t.mtlSpec}, #{t.mtlUnit}, #{t.usage}, #{t.usageType}, #{t.mtlTypeNo}, #{t.vendor}, #{t.stdUsage}, #{t.ttlUsage}, #{t.remark}, #{t.sumUsage}, #{t.drawDept}, #{t.mtlProperty}, #{t.addUsage}, #{t.mtlLevel})",
            "</foreach>",
            "</script>"
    })
    void addPcLotUsageList(@Param("pcLotUsageList") List<PcLotUsage> pcLotUsageList);

    /**
     * 审核
     * @param lotNo
     * @param userName
     * @param CheckFlag
     * @param now
     */
    @Update("update PC_LOT_HEAD set CHECK_FLAG=#{CheckFlag},CHECK_DATE=#{now},CHECK_USER=#{userName} where LOT_NO=#{lotNo} and COMPANY_ID=#{companyId}")
    void updateLotNoCheckUp(@Param("lotNo") String lotNo,
                            @Param("companyId") String companyId,
                            @Param("userName") String userName,
                            @Param("CheckFlag") String CheckFlag,
                            @Param("now") LocalDateTime now);

    /**
     * 删除全部po号码明细
     *
     * @param lotNo
     * @param companyId
     */
    @Delete("delete from PC_LOT_GROUP where LOT_NO=#{lotNo} and COMPANY_ID=#{companyId}")
    void delPcLotGroupAll(@Param("lotNo") String lotNo, @Param("companyId") String companyId);

    /**
     * 删除全部指令号码明细
     *
     * @param lotNo
     * @param companyId
     */
    @Delete("delete from PC_LOT_DETAIL where LOT_NO=#{lotNo} and COMPANY_ID=#{companyId}")
    void delPcLotDetailAll(@Param("lotNo") String lotNo, @Param("companyId") String companyId);

    /**
     * 写入指令删除日志
     * @param delLog
     */
    @Insert("INSERT INTO PC_LOT_DEL_LOG (COMPANY_ID, LOT_NO, SYS_USER, SYS_DATE, LOT_TYPE)VALUES (#{companyId}, #{lotNo}, #{sysUser}, #{sysDate}, #{lotType})")
    void addPcLotDelLog(PcLotDelLog delLog);

    /**
     * 查询指令信息
     *
     * @param lotNo
     * @param companyId
     * @return
     */
    @Select("SELECT t3.ABBR_NAME as companyId,t3.LOT_NO,t3.STYLE,t3.COLOR,t3.CUSTOM,t3.ORDER_QTY,t3.SURPLUS_QTY,t2.PHOTO_PATH from SD_STYLE_COLOR_PHOTO t2 LEFT JOIN" +
            "(SELECT t1.ABBR_NAME,t.LOT_NO,t.STYLE,t.COLOR,t.CUSTOM,t.ORDER_QTY,t.SURPLUS_QTY,t.COMPANY_ID from PC_LOT_HEAD t LEFT JOIN SD_COMPANY t1 on t.COMPANY_ID=t1.COMPANY_ID)t3 on" +
            " t3.STYLE=t2.STYLE_NO and t3.COLOR=t2.STYLE_COLOR AND t2.COMPANY_ID=t3.COMPANY_ID where t3.LOT_NO=#{lotNo} and t3.COMPANY_ID=#{companyId}")
    PunchingExportVo getPcLotHead(@Param("lotNo") String lotNo, String companyId);

    /*外接单价-指令资料查询*/
    List<OutUnitPriceVo> listPcDhLot(@Param("request") PcDhLotRequest request, @Param("companyId") String companyId);

    /*外接单价金额求和*/
    Map<String, Object> outUnionPriceSum(@Param("request") PcDhLotRequest request, @Param("companyId") String companyId);

    /**
     * 查询型体颜色是否存在
     *
     * @param style
     * @param color
     * @param companyId
     */
    @Select("select count(1) from PC_LOT_HEAD where STYLE=#{style} and COLOR=#{color} and COMPANY_ID=#{companyId}")
    Integer getStyleToColor(String style, String color, String companyId);

    /**
     * 根据指令查询型体颜色
     *
     * @param lotNo
     * @param companyId
     * @return
     */
    @Select("select LOT_NO,STYLE,COLOR from PC_LOT_HEAD where LOT_NO=#{lotNo} AND COMPANY_ID=#{companyId}")
    LotNoDetailDto getLotNoDetail(@Param("lotNo") String lotNo, @Param("companyId") String companyId);

    /*批量查询所有指令信息*/
    List<PcLotHeadDto> getBatchStyleDetails(@Param("lotNoList") List<String> lotNoList, @Param("companyId") String companyId);

    List<PcAggScheduleExcel> downloadPcAggSchedule();

    /**
     * 批量查询指令信息
     * @param lotNos
     * @param companyId
     * @return
     */
    List<PcLotHead> selectByLotNos(List<String> lotNos,String companyId);

    /**
     * 视图PC_V_CUT_QUERY_LOT
     *
     * @param request   查询条件
     * @param companyId
     * @return 指令集合
     */
    List<PcLotHead> pcVCutQueryLot(@Param("request") LotStyleRerquest request, String companyId);

    OemLotHead selectByFactoryLotNo(OemLotHead oemLotHead);

    void deleteByUUID(OemLotHead tempHead);

    int selectPayCfmCount(@Param("companyId") String companyId, @Param("factoryLotNo") String factoryLotNo);

    int selectCfmCount(@Param("companyId") String companyId, @Param("factoryLotNo") String factoryLotNo);

    void insertOperlog(SysOperLog param);

    /**
     * 补单派工打印数据查询
     * @param request 查询条件
     * @param processCode 工艺ID
     * @param companyId 公司ID
     * @return 派工数据
     */
    SuppDispatchPrintDto suppDispatchPrintQuery(@Param("request") SuppDispatchPrintRequest request, @Param("processCode") String processCode, @Param("companyId") String companyId);

    /*指令明细和明细子材料*/
    List<PcLotUsageDto> getUsageAndSubMaterial(@Param("lotNo") String lotNo, @Param("companyId") String companyId);

    List<PcLotUsageDto> getUsageAndSubMaterial2(@Param("lotNo") String lotNo, @Param("companyId") String companyId);

    /*要对汇总数据进行判断，如果某个指令的材料有材料名称一样，但是编码不同的指令会报错*/
    List<PcLotUsageDto> judgeUsageAndSubMaterial(List<String> lotList, String companyId);

    /**
     * 生成指令用量记录
     * @param lotUsageHead
     * @return
     */
    int addPcLotUsageHead(PcLotUsageHead lotUsageHead);

    /**
     * 删除指令用量记录
     * @param lotNo
     * @param companyId
     * @return
     */
    @Delete("delete from PC_LOT_USAGE_HEAD where LOT_NO=#{lotNo} and COMPANY_ID=#{companyId}")
    int delPcLotUsageHead(@Param("lotNo") String lotNo, @Param("companyId") String companyId);

    /**
     * 查询指令用量记录
     * @param lotNo
     * @param companyId
     * @return
     */
    @Select("select * from PC_LOT_USAGE where LOT_NO=#{lotNo} and COMPANY_ID=#{companyId}")
    List<PcLotUsage> getPcLotUsageList(@Param("lotNo") String lotNo, @Param("companyId") String companyId);

    /**
     * 查询bom资料下子材料
     * @param style
     * @param color
     * @param companyId
     */
    @Select("SELECT t.COMPANY_ID,t.SEQ_NO,t.PART_NAME,t.SEGMENT,t2.MTL_NO,t2.MTL_COLOR,t2.MTL_NAME,t2.MTL_SPEC,t2.MTL_UNIT,t2.SUB_MTL_NO,t2.SUB_MTL_NAME,t2.SUB_MTL_COLOR,t2.SUB_MTL_SPEC,t2.SUB_MTL_UNIT,t2.PERCENT,t2.PUR_FLAG " +
            "from SD_BOM_PART_NEW2 t RIGHT JOIN SD_BOM_FIT_SUB t2 on t.MTL_NO2=t2.MTL_NO and t.COMPANY_ID=t2.COMPANY_ID WHERE t.STYLE_NO=#{style} AND t.STYLE_COLOR=#{color} and t.COMPANY_ID=#{companyId} and t2.PUR_FLAG='Y'")
    List<PcLotUsageFit> getSdBomFitSubList(@Param("style") String style, @Param("color") String color, @Param("companyId") String companyId);

    /**
     * 新增指令用量子材料
     * @param sdBomFitSubList
     * @return
     */
    int addPcLotUsageFit(@Param("sdBomFitSubList") List<PcLotUsageFit> sdBomFitSubList);

    /**
     * 查询子材料信息
     * @param lotNo
     * @param companyId
     * @return
     */
    @Select("select * from PC_LOT_USAGE_FIT where LOT_NO=#{lotNo} and COMPANY_ID=#{companyId} ")
    List<PcLotUsageFit> getPcLotUsageFitList(String lotNo, String companyId);

    /**
     * 新增指令用量记录
     * @param pcLotUsageChgList
     * @return
     */
    int addPcLotUsageChgList(@Param("pcLotUsageChgList") List<PcLotUsageChg> pcLotUsageChgList);

    /**
     * 新增指令用量子材料记录
     * @param pcLotUsageChgFitList
     * @return
     */
    int addPcLotUsageFitChgList(@Param("pcLotUsageChgFitList") List<PcLotUsageFitChg> pcLotUsageChgFitList);

    /**
     * 查找同配色指令
     * @param pcLotHead
     * @return
     */
    List<String> getOtherLotNoByHead(PcLotHead pcLotHead);

    /**
     * 指令下拉列表
     * @param companyId
     * @param lotNo
     * @return
     */
    List<String> getLotNoList(@Param("companyId") String companyId, @Param("lotNo") String lotNo);

    /*根据指令批量查询号码明细数据*/
    List<String> getBatchCode(@Param("list") List<String> lotNos, @Param("companyId") String companyId);

    /*根据指令批量查询的号码的数量*/
    List<PcLotDetailDto> getBatchCodeDetails(@Param("list") List<String> lotNos, @Param("companyId") String companyId);

    /*查询当前指令是否有翻单的指令：前一单形体配色相同*/
    String getRepeatLotNo(PcLotHead pcLotHead);

    /**
     * 查询型体颜色资料
     * @param style
     * @param color
     * @param companyId
     * @return
     */
    StyleDataDto getSdStyleColorPhoto(@Param("style") String style,
                                           @Param("color") String color,
                                           @Param("companyId") String companyId);

    /*清洗PC_LOT_USAGE数据*/
    int cleanPcLotUsage(String companyId, List<CleanDataDto> list);

    /*清洗 PC_LOT_USAGE_FIT 数据*/
    int cleanPcLotUsageFit(String companyId, List<CleanDataDto> list);


    /**
     *
     * 判断是否生成指令用量明细
     * @param lotNo
     * @param companyId
     * @return
     */
    Integer getPcLotUsages(@Param("lotNo") String lotNo, @Param("companyId") String companyId);

    /*pcLotUsageChg*/
    void addPcLotUsageChg(PcLotUsageChg pcLotUsageChg);
    /**
     * 账目库存导出补充数据
     * @param accList 查询条件
     * @return 导出数据
     */
    List<StkAccDto> stkAccExportQuery(@Param("accList") List<StkAccDto> accList);

    /**
     * 查询号码类型
     * @param lotNo
     * @param companyId
     * @return
     */
    @Select("SELECT t2.SIZE_TYPE from PC_LOT_HEAD t LEFT JOIN SD_STYLE t2 on t.STYLE=t2.STYLE_NO and t.COMPANY_ID=t2.COMPANY_ID where t.LOT_NO=#{lotNo} and t.COMPANY_ID=#{companyId}")
    String getSizeType(@Param("lotNo") String lotNo, @Param("companyId") String companyId);

    /*查询指令单的鞋托数据*/
    List<PcLotUsageDto> getDetailsOfShoes(String lotNo, String companyId);

    /**
     * 根据指令获取品牌
     * @param lotList 指令集合指令集合
     * @return 键：指令 /值：品牌
     */
    Map<String, String> getCustomByLot(@Param("lotList") List<String> lotList);

    /**
     * 获取订单交期分析
     */
    List<DeliveryListDto> getOrdDlvList(@Param("dateFlag") int dateFlag, @Param("startDate") LocalDateTime startDate, @Param("endDate") LocalDateTime endDate, @Param("companyId") String companyId);

    /**
     * 订单交期细节数据
     */
    List<DelDetDto> getDelDetailList(@Param("startDate") LocalDate startDate, @Param("endDate") LocalDate endDate, @Param("type") Integer type, @Param("companyId") String companyId);
}
